package com.gjzt.business.bid.service;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eastdigit.servlet.ReqBean;
import com.eastdigit.system.model.BusinessException;
import com.eastdigit.system.model.SqlBuilder;
import com.eastdigit.system.service.BaseService;
import com.eastdigit.util.DateUtil;
import com.eastdigit.util.StringUtil;
import com.gjzt.business.bid.inter.BiddingRecordMapper;
import com.gjzt.business.bid.model.BiddingRecord;
import com.gjzt.business.depositOrder.inter.DepositOrderMapper;
import com.gjzt.business.depositOrder.model.DepositOrder;
import com.gjzt.business.media.service.MediaFileService;
import com.gjzt.business.publish.inter.MakeBillDetailMapper;
import com.gjzt.business.publish.inter.PublishBillMapper;
import com.gjzt.business.publish.model.MakeBillDetail;
import com.gjzt.business.publish.model.PublishBill;
import com.gjzt.business.utils.Constant;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service
public class BiddingForExternalService extends BaseService {

    @Autowired
    private BiddingRecordMapper biddingRecordMapper;
    @Autowired
    private MediaFileService mediaFileService;
    @Autowired
    private MakeBillDetailMapper makeBillDetailMapper;
    @Autowired
    private PublishBillMapper publishBillMapper;
    @Autowired
    private DepositOrderMapper depositOrderMapper;
    

    private void verifyCustomerLogin(String customerId){
    	 if (StringUtils.isBlank(customerId)) {
             throw new BusinessException("获取不到客户信息，请先登录!");
         }
    }
    
	/**
	 * 查询
	 *
	 * @param reqBean
	 * @return
	 */
	public JSONObject findAdBidding(ReqBean reqBean) {
		JSONObject result = new JSONObject();
		SqlBuilder sqlBuilder = new SqlBuilder("select   ab.*,ac.CUSTOMER_NAME"
				+ " from AD_BIDDING  ab LEFT JOIN AD_CUSTOMER ac on ab.CUSTOMER_ID=ac.CUSTOMER_ID where 1=1 and ab.`STATUS`<> 0 ");
		sqlBuilder.addWhereLike2("ab.BID_TITLE", reqBean.getInfo("bidTitle"))
				.addWhere("ab.STATUS", reqBean.getInfo("status")).addWhere("ab.BID_ID", reqBean.getInfo("bidId"))
				.addTimeWhere("ab.START_DATE", reqBean.getInfo("startDate"), ">=")
				.addTimeWhere("ab.END_DATE", reqBean.getInfo("endDate"), "<=");
		sqlBuilder.appendSql(" order by ab.`STATUS`,ab.PUBLISH_TIME desc");
		JSONObject dataJson = this.queryTable(sqlBuilder, reqBean.getInfoInt("pageSize"),
				reqBean.getInfoInt("pageIndex"));
		int totalPages = dataJson.getInt("total") % reqBean.getInfoInt("pageSize") == 0
				? dataJson.getInt("total") / reqBean.getInfoInt("pageSize")
				: dataJson.getInt("total") / reqBean.getInfoInt("pageSize") + 1;
		result.put("dataArray", dataJson.getJSONArray("rows"));// 最终数据
		result.put("totalPages", totalPages);// 总页数
		return result;
	}

	
	public JSONObject findBidByBidId(ReqBean reqBean) {
		JSONObject result = new JSONObject();
		String bidId = reqBean.getInfo("bidId");
		SqlBuilder sqlBuilder = new SqlBuilder("select   ab.*  from AD_BIDDING  ab where ab.BID_ID='");
		sqlBuilder.appendSql(bidId);
		sqlBuilder.appendSql("'");
		JSONArray bidArray = this.query(sqlBuilder);
		if(bidArray!=null && bidArray.size()>0){
			result.put("bid", bidArray.getJSONObject(0));	
		}
		return result;
	}
	
	/**
	 * 查询出价记录
	 * @param reqBean
	 * @return
	 */
	public JSONObject findBidRecordInfo(ReqBean reqBean) {
		JSONObject result = new JSONObject();
		String bidId = reqBean.getInfo("bidId");
		String  getBidRecodeSlq = "select abr.*,ac.CUSTOMER_NAME from AD_BIDDING_RECORD  abr "
				+ "left join AD_CUSTOMER ac on abr.CUSTOMER_ID = ac.CUSTOMER_ID "
				+ "where abr.BID_ID='" + bidId + "' ORDER BY abr.BID_PRICE desc ";
		JSONArray bidRecodeArray = this.query(getBidRecodeSlq);
		if (bidRecodeArray != null && bidRecodeArray.size() > 0) {// 更改状态、中标信息
			JSONObject json = bidRecodeArray.getJSONObject(0);// 取最高出价者
			result.put("topRecord", json);
		}
		result.put("bidRecordArray", bidRecodeArray);
		return result;
	}
	
	 /**
     * 查询客户所有资源
     * 
     * @param reqBean
     * @return
     */
    public JSONObject findCustomerResource(ReqBean reqBean) {
        JSONObject result = new JSONObject();
        
        String customerId = reqBean.getInfo("customerId");//客户id
        verifyCustomerLogin(customerId);
        String resourceParentType = reqBean.getInfo("resourceParentType");// 资源父类型
        String resourceType = reqBean.getInfo("resourceType");// 资源子类型
        String resourceCode = reqBean.getInfo("resourceCode");// 资源编号
        String contractId = reqBean.getInfo("contractId");// 合同id
        String contractTitle = reqBean.getInfo("contractTitle");// 合同id
        
       
        
        SqlBuilder sql = new SqlBuilder("SELECT ac.CONTRACT_ID, ac.CONTRACT_NO, ac.CONTRACT_TITLE, ac.CUSTOMER_ID, acr.RESOURCE_ID,acr.START_DATE,acr.END_DATE, mr.RESOURCE_NAME, mr.RESOURCE_CODE,mr.MODEL ,t.MEDIA_NAME");
       
        if(Constant.MEDIA_TYPE_STOP.equals(resourceParentType)){// 站点
            sql.appendSql(" ,s.STOP_NAME, s.ROAD_NAME ");
        }else if(Constant.MEDIA_TYPE_BUS.equals(resourceParentType)){
     	   sql.appendSql(" ,b.PLATE_NO, b.LINE_NO ");
        }
        
        sql.appendSql(" FROM AD_CONTRACT ac");
        sql.appendSql(" inner JOIN AD_CONTRACT_RESOURCE acr ON ac.CONTRACT_ID = acr.CONTRACT_ID");
        sql.appendSql(" inner JOIN MEDIA_RESOURCE mr ON mr.RESOURCE_ID = acr.RESOURCE_ID");
        sql.appendSql(" INNER JOIN MEDIA_TYPE t on  mr.MEDIA_TYPE = t.MEDIA_ID ");
        
        if(Constant.MEDIA_TYPE_STOP.equals(resourceParentType)){// 站点
               sql.appendSql(" LEFT JOIN MEDIA_STOP s ON mr.STOP_ID = s.STOP_ID");
        }else if(Constant.MEDIA_TYPE_BUS.equals(resourceParentType)){
               sql.appendSql(" LEFT JOIN MEDIA_BUS b ON mr.BUS_ID = b.BUS_ID");
        }
        sql.appendSql(" where 1=1 and ac.CUSTOMER_ID ='");
        sql.appendSql(customerId);
        sql.appendSql("' ");
        sql.addWhere("t.PARENT_ID", resourceParentType);
        sql.addWhere("mr.MEDIA_TYPE", resourceType);
        sql.addWhereLike2("mr.RESOURCE_CODE", resourceCode);
        sql.addWhere("ac.CONTRACT_ID", contractId);
        sql.addWhereLike2("ac.CONTRACT_NO", contractTitle);
        
    	JSONObject dataJson = this.queryTable(sql, reqBean.getInfoInt("pageSize"),reqBean.getInfoInt("pageIndex"));
    	JSONArray dataArray = dataJson.getJSONArray("rows");
        
    	int totalPages = dataJson.getInt("total") % reqBean.getInfoInt("pageSize") == 0
				? dataJson.getInt("total") / reqBean.getInfoInt("pageSize")
				: dataJson.getInt("total") / reqBean.getInfoInt("pageSize") + 1;
		result.put("dataArray", dataArray);// 最终数据
		result.put("totalPages", totalPages);// 总页数
		return result;
        
        
    }
    
    /**
     * 获得客户参与过竞价的信息
     * @param reqBean
     * @return
     */
    public JSONObject getCustomerBidsInfo(ReqBean reqBean){
    	
    	JSONObject result = new JSONObject();
    	String customerId =  reqBean.getInfo("customerId");// 客户id
    	verifyCustomerLogin(customerId);
    	String bidCode =  reqBean.getInfo("bidCode");// 竞价单编号
    	
    	SqlBuilder sql = new SqlBuilder("select  abd.*,ac.CUSTOMER_NAME,ab.BID_TITLE,ab.STATUS,ab.BID_CODE,ab.PUBLISH_TIME,ab.LIMIT_TIME,(case when ab.CUSTOMER_ID=abd.CUSTOMER_ID then 1 else 0  end ) as bidStatus from  AD_BIDDING_DEPOSIT abd ");
    	sql.appendSql("LEFT JOIN AD_CUSTOMER ac on abd.CUSTOMER_ID = ac.CUSTOMER_ID ");
    	sql.appendSql("LEFT JOIN AD_BIDDING ab on ab.BID_ID= abd.BID_ID where 1=1 and abd.CUSTOMER_ID ='");
    	sql.appendSql(customerId);
    	sql.appendSql("' ");
    	sql.addWhereLike2("ab.BID_CODE", bidCode);
    	sql.appendSql("ORDER BY ab.PUBLISH_TIME desc");
    	JSONObject dataJson = this.queryTable(sql, reqBean.getInfoInt("pageSize"),reqBean.getInfoInt("pageIndex"));
    	JSONArray dataArray = dataJson.getJSONArray("rows");
    	
    	for (int i = 0; i < dataArray.size(); i++) {
			JSONObject json = dataArray.getJSONObject(i);
			String bidId = json.getString("bidId");
			String customerIdX = json.getString("customerId");
			String getBidRecord = "select  *  from AD_BIDDING_RECORD abr  where abr.BID_ID='"+bidId+"' and abr.CUSTOMER_ID='"+customerIdX+"' ORDER BY abr.BIDDING_TIME desc";
			JSONArray bidRecordArray = this.query(getBidRecord);
			json.put("bidRecordArray", bidRecordArray);
		}
    	
		int totalPages = dataJson.getInt("total") % reqBean.getInfoInt("pageSize") == 0
				? dataJson.getInt("total") / reqBean.getInfoInt("pageSize")
				: dataJson.getInt("total") / reqBean.getInfoInt("pageSize") + 1;
		result.put("dataArray", dataArray);// 最终数据
		result.put("totalPages", totalPages);// 总页数
		return result;
    }
    
    
    
    /**
     * 查询客户保证金信息
     * @param reqBean
     * @return
     */
    
    public JSONObject getCustomerDeposit(ReqBean reqBean){
    	JSONObject result = new JSONObject();
    	String bidId = reqBean.getInfo("bidId");
    	String customerId = reqBean.getInfo("customerId");
    	if(StringUtil.isEmpty(customerId)){// 没有客户信息
    		JSONArray dataArray = new JSONArray();
			result.put("dataArray", dataArray);
		}else {
			verifyCustomerLogin(customerId);
	    	String sql = "select  *  from AD_BIDDING_DEPOSIT  abd  where abd.BID_ID ='"+bidId+"' and abd.CUSTOMER_ID='"+customerId+"'";
	    	JSONArray dataArray = this.query(sql);
	    	result.put("dataArray", dataArray);
		}
    	return result;
    }
    
    
    /**
     * 查询客户支付中的订单信息
     * @param reqBean
     * @return
     */
	public JSONObject getCustomerDepositOrder(ReqBean reqBean) {
		JSONObject result = new JSONObject();
		String bidId = reqBean.getInfo("bidId");
		String customerId = reqBean.getInfo("customerId");
		if(StringUtil.isEmpty(customerId)){// 没有客户信息
			result.put("hasPayingOrder", false);
		}else {
			DepositOrder depositOrder = depositOrderMapper.selectByBidIdAndCustomerIdAndStatus(bidId, customerId, Constant.DEPOSIT_ORDER_STATUS_PAY_ING);
			if (depositOrder != null) {// 客户存在支付保证金订单
				result.put("hasPayingOrder", true);
			} else {
				result.put("hasPayingOrder", false);
			}
		}
		return result;
	}
    
    /**
     * 查询客户上刊单信息
     * 
     * @param reqBean
     * @return
     */
	public JSONObject findAdPublishBill(ReqBean reqBean) {
		String customerId = reqBean.getInfo("customerId");
		verifyCustomerLogin(customerId);
		JSONObject result = new JSONObject();
		SqlBuilder sqlBuilder = new SqlBuilder(
				"SELECT a.BILL_ID,a.BILL_NO,a.APPLY_TIME,a.BILL_TYPE,a.content,a.PUBLISH_TIME ,a.PUBLISH_OFF_TIME, a.AUDIT_TIME,a.STATUS publishBillStatus, ");
		sqlBuilder.appendSql("a.AUDITOR,a.COMMENT,ad.* FROM `AD_PUBLISH_BILL` a left join AD_CUSTOMER ad ");
		sqlBuilder.appendSql("ON ad.CUSTOMER_ID = a.CUSTOMER_ID where 1=1 and a.CUSTOMER_ID ='");
		sqlBuilder.appendSql(customerId);
		sqlBuilder.appendSql("' ");
		sqlBuilder.addWhereLike2("a.BILL_NO", reqBean.getInfo("billNo"))
				.addWhere("a.STATUS", reqBean.getInfo("status"));
		sqlBuilder.appendSql(" ORDER BY a.STATUS asc,a.APPLY_TIME desc");
		JSONObject dataJson = this.queryTable(sqlBuilder, reqBean.getInfoInt("pageSize"),
				reqBean.getInfoInt("pageIndex"));
		int totalPages = dataJson.getInt("total") % reqBean.getInfoInt("pageSize") == 0
				? dataJson.getInt("total") / reqBean.getInfoInt("pageSize")
				: dataJson.getInt("total") / reqBean.getInfoInt("pageSize") + 1;
		result.put("dataArray", dataJson.getJSONArray("rows"));// 最终数据
		result.put("totalPages", totalPages);// 总页数
		return result;
	}
	
	
	  /**
     * 制作单查询
     * 将明细放入制作单内
     * @param reqBean
     * @return
     */
   /* public JSONObject queryMakeBill(ReqBean reqBean) {
    	String customerId = reqBean.getInfo("customerId");
    	verifyCusntomerLogin(customerId);
    	JSONObject result = new JSONObject();
        String sql = "SELECT a.*,pb.BILL_TYPE,pb.AUDIT_TIME,c.* FROM `AD_PUBLISH_MAKE_BILL` a "
                + "LEFT JOIN AD_PUBLISH_BILL pb ON pb.BILL_ID = a.BILL_ID LEFT JOIN AD_CUSTOMER c ON c.CUSTOMER_ID = pb.CUSTOMER_ID WHERE 1=1 and pb.CUSTOMER_ID ='"+customerId+"' ";
        SqlBuilder sqlBuilder = new SqlBuilder(sql).addWhereLike2("ad.CUSTOMER_NAME", reqBean.getInfo("customerName"))
                .addWhereLike2("a.BILL_NO", reqBean.getInfo("billNo"))
                .addWhere("pb.BILL_ID", reqBean.getInfo("billId"));
        sqlBuilder.appendSql(" ORDER BY pb.APPLY_TIME DESC");
        JSONObject dataJson = this.queryTable(sqlBuilder, reqBean.getInfoInt("pageSize"),
				reqBean.getInfoInt("pageIndex"));
		int totalPages = dataJson.getInt("total") % reqBean.getInfoInt("pageSize") == 0
				? dataJson.getInt("total") / reqBean.getInfoInt("pageSize")
				: dataJson.getInt("total") / reqBean.getInfoInt("pageSize") + 1;
		result.put("dataArray", dataJson.getJSONArray("rows"));// 最终数据
		result.put("totalPages", totalPages);// 总页数
		return result;
    }*/
    
    /**
     *  制作单查询
     * 将明细放入制作单内
     * @param reqBean
     * @return
     */
    public JSONObject queryMakeBillInfo(ReqBean reqBean) {
    	String customerId = reqBean.getInfo("customerId");
    	verifyCustomerLogin(customerId);
    	 String billId = reqBean.getInfo("billId");
         if (StringUtils.isBlank(billId)) {
             throw new BusinessException("缺少参数!");
         }
    	JSONObject result = new JSONObject();
        String sql = "SELECT a.*,pb.BILL_TYPE,pb.AUDIT_TIME,c.* FROM `AD_PUBLISH_MAKE_BILL` a "
                + "LEFT JOIN AD_PUBLISH_BILL pb ON pb.BILL_ID = a.BILL_ID LEFT JOIN AD_CUSTOMER c ON c.CUSTOMER_ID = pb.CUSTOMER_ID WHERE 1=1 and pb.CUSTOMER_ID ='"+customerId+"' ";
        SqlBuilder sqlBuilder = new SqlBuilder(sql).addWhereLike2("ad.CUSTOMER_NAME", reqBean.getInfo("customerName"))
                .addWhereLike2("a.BILL_NO", reqBean.getInfo("billNo"))
                .addWhere("pb.BILL_ID", reqBean.getInfo("billId"));
        sqlBuilder.appendSql(" ORDER BY pb.APPLY_TIME DESC");
        JSONArray makeBillArray = this.query(sqlBuilder);
        
        for (int i = 0; i < makeBillArray.size(); i++) {
        	JSONObject makeBill = makeBillArray.getJSONObject(i);
        	String makeBillId = makeBill.getString("makeBillId");
        	//获取制作单明细
        	makeBill.put("makeBillDetailsArray", queryMakeBillDetails(makeBillId));
		}
        result.put("dataArray", makeBillArray);
		return result;
    }
    
    
    public JSONArray queryMakeBillDetails( String makeBillId) {
        if (StringUtils.isBlank(makeBillId)) {
            throw new BusinessException("缺少参数!");
        }
        String sql = "select a.MAKE_BILL_ID,a.STATUS makeBillDetailStatus ,a.REMARK makeBillDetailRemark,a.COMPLETE_TIME,"
                + "a.PUBLISH_DETAIL_ID,mr.*,mt.MEDIA_NAME,s.STOP_NAME,s.ROAD_NAME,s.DIRECTION,b.VEHICLE_NO,b.PLATE_NO,b.LINE_NO,"
                + "b.COMPANY_ID,b.COMPANY_NAME,"
                + "b.BUS_FLOOR,pb.PUBLISH_TIME,pb.PUBLISH_OFF_TIME,pbd.PUBLISH_FILE,pbd.CONTENT,pb.BILL_TYPE "
                + "FROM AD_PUBLISH_MAKE_BILL_DETAIL a LEFT JOIN AD_PUBLISH_BILL_DETAIL pbd ON a.PUBLISH_DETAIL_ID = pbd.ID "
                + "LEFT JOIN AD_PUBLISH_BILL pb ON pb.BILL_ID = pbd.BILL_ID "
                + "LEFT JOIN MEDIA_RESOURCE mr ON mr.RESOURCE_ID = pbd.RESOURCE_ID "
                + "LEFT JOIN MEDIA_TYPE mt ON mt.MEDIA_ID = mr.MEDIA_TYPE "
                + "LEFT JOIN MEDIA_STOP s ON mr.STOP_ID = s.STOP_ID "
                + "LEFT JOIN MEDIA_BUS b ON mr.BUS_ID = b.BUS_ID where 1=1 ";
        SqlBuilder sqlBuilder = new SqlBuilder(sql).addWhere("a.MAKE_BILL_ID", makeBillId);
        JSONArray makeBillDetailsArray = this.query(sqlBuilder);
        
        //将完工照图样放入记录中
        for (int i = 0; i < makeBillDetailsArray.size(); i++) {
        	JSONObject o = makeBillDetailsArray.getJSONObject(i);
        	String publishDetailId = o.getString("publishDetailId");
        	o.put("imgs", mediaFileService.getMediaFileArrayBySourceTypeAndDataId(Constant.MEDIAFILE_SOURCE_TYPE_FINISHED, publishDetailId, Constant.DATA_STATUS_TRUE));
		}
        return  makeBillDetailsArray;// 最终数据
    }
	
    /**
     * 制作单详情查询
     * @param reqBean
     * @return
     */
    /*public JSONObject queryMakeBillDetails(ReqBean reqBean) {
    	JSONObject result = new JSONObject();
        String makeBillId = reqBean.getInfo("makeBillId");
        if (StringUtils.isBlank(makeBillId)) {
            throw new BusinessException("缺少参数!");
        }
        String sql = "select a.MAKE_BILL_ID,a.STATUS makeBillDetailStatus ,a.REMARK makeBillDetailRemark,a.COMPLETE_TIME,"
                + "a.PUBLISH_DETAIL_ID,mr.*,mt.MEDIA_NAME,s.STOP_NAME,s.ROAD_NAME,s.DIRECTION,b.VEHICLE_NO,b.PLATE_NO,b.LINE_NO,"
                + "b.COMPANY_ID,"
                +" (select c.CODE_NAME  from SYS_CODE  c where c.CODE_TYPE='BUS_COMPANY' and c.CODE_VALUE=b.COMPANY_ID) as companyName,"
                + "b.BUS_FLOOR,pb.PUBLISH_TIME,pb.PUBLISH_OFF_TIME,pbd.PUBLISH_FILE,pbd.CONTENT,pb.BILL_TYPE "
                + "FROM AD_PUBLISH_MAKE_BILL_DETAIL a LEFT JOIN AD_PUBLISH_BILL_DETAIL pbd ON a.PUBLISH_DETAIL_ID = pbd.ID "
                + "LEFT JOIN AD_PUBLISH_BILL pb ON pb.BILL_ID = pbd.BILL_ID "
                + "LEFT JOIN MEDIA_RESOURCE mr ON mr.RESOURCE_ID = pbd.RESOURCE_ID "
                + "LEFT JOIN MEDIA_TYPE mt ON mt.MEDIA_ID = mr.MEDIA_TYPE "
                + "LEFT JOIN MEDIA_STOP s ON mr.STOP_ID = s.STOP_ID "
                + "LEFT JOIN MEDIA_BUS b ON mr.BUS_ID = b.BUS_ID where 1=1 ";
        SqlBuilder sqlBuilder = new SqlBuilder(sql).addWhere("a.MAKE_BILL_ID", makeBillId);
        
        JSONObject dataJson = this.queryTable(sqlBuilder, reqBean.getInfoInt("pageSize"),
				reqBean.getInfoInt("pageIndex"));
		int totalPages = dataJson.getInt("total") % reqBean.getInfoInt("pageSize") == 0
				? dataJson.getInt("total") / reqBean.getInfoInt("pageSize")
				: dataJson.getInt("total") / reqBean.getInfoInt("pageSize") + 1;
		JSONArray dataArray = dataJson.getJSONArray("rows");
        
        //将完工照图样放入记录中
        for (int i = 0; i < dataArray.size(); i++) {
        	JSONObject o = dataArray.getJSONObject(i);
        	String publishDetailId = o.getString("publishDetailId");
        	o.put("imgs", mediaFileService.getMediaFileArrayBySourceTypeAndDataId(Constant.MEDIAFILE_SOURCE_TYPE_FINISHED, publishDetailId, Constant.DATA_STATUS_TRUE));
		}
        result.put("dataArray", dataArray);// 最终数据
		result.put("totalPages", totalPages);// 总页数
		return result;
    }*/
	
	/**
	 * 客户出价
	 * @param reqBean
	 */
	public void offerPrice(ReqBean reqBean) {
		String customerId = reqBean.getInfo("customerId");
		verifyCustomerLogin(customerId);
		BiddingRecord biddingRecord = new BiddingRecord();
		biddingRecord.setId(intIncrementId("AD_BIDDING_RECORD", "ID"));// 手动设置Id
		biddingRecord.setBidId(reqBean.getInfo("bidId"));
		biddingRecord.setCustomerId(customerId);
		biddingRecord.setBidPrice(reqBean.getInfoDouble("payPrice"));
		biddingRecord.setBiddingTime(new Date());// 缴费记录
		biddingRecordMapper.insert(biddingRecord);
	}
    
    /**
     * 完工时间、图片处理
     * @param reqBean
     */
    public void completeBill(ReqBean reqBean) {
        String makeBillId = reqBean.getInfo("makeBillId");// 制作单id
        String publishDetailId = reqBean.getInfo("publishDetailId");// 上刊单明细id(对应到具体的资源)
        if(StringUtils.isBlank(makeBillId) || StringUtils.isBlank(publishDetailId)) {
            throw new BusinessException("缺少参数!");
        }
        
        //插入完工照
       JSONObject img = JSONObject.fromObject(reqBean.getInfoObj("img"));
       JSONArray imgsArray = new JSONArray();
       imgsArray.add(img);
       JSONObject fileDataJson = mediaFileService.getDataJson(Constant.MEDIAFILE_SOURCE_TYPE_FINISHED, publishDetailId, imgsArray);
       if(imgsArray.size()>0 && fileDataJson!=null){
    	   mediaFileService.addMediaFile(fileDataJson);
       }
      
        MakeBillDetail makeBillDetail = makeBillDetailMapper.selectByPrimaryKey(makeBillId, publishDetailId);
        makeBillDetail.setCompleteTime(DateUtil.parseDateTime(reqBean.getInfo("completeTime")));
        makeBillDetail.setStatus(Constant.PUBLISH_MAKE_BILL_DETAIL_STATUS_COMPLETED);
        makeBillDetail.setRemark(reqBean.getInfo("makeBillDetailRemark"));
        makeBillDetailMapper.updateByPrimaryKey(makeBillDetail);

    }
    
    /**
     * 全部完工
     * 直接改变上刊单的状态，改为“已完工”
     * @param reqBean
     */
	public void finishAll(ReqBean reqBean) {
		String billId = reqBean.getInfo("billId");
		PublishBill publishBill = publishBillMapper.selectByPrimaryKey(billId);
		publishBill.setStatus(Constant.PUBLISH_BILL_STATUS_FINISHED); // 已完工
		publishBillMapper.updateByPrimaryKeySelective(publishBill);
	}
    
	
}